# -*- coding: utf-8 -*- 
# 作者:飞虎
# 开发时间:2022/5/6 11:16
# 0. 导入需要的包和模块
from PyQt5.Qt import *
import sys

# 1. 创建一个应用程序对象
app = QApplication(sys.argv)
# 2. 控件的操作
# 2.1 创建控件
window = QWidget()
# 2.2 设置控件
window.setWindowTitle('QLineEdit-功能测试')
window.resize(500, 500)

le = QLineEdit(window)
le.move(100, 100)
le.resize(300, 300)

btn = QPushButton(window)
btn.setText('按钮')
btn.move(50, 50)
# le.setContentsMargins(100,0,0,0)
le.setStyleSheet('background-color:cyan')
le.setTextMargins(00, 00, 50, 50)
le.setAlignment(Qt.AlignRight | Qt.AlignBottom)
le.setDragEnabled(True)

le2 = QLineEdit(window)
le2.resize(50, 50)
le2.move(200, 0)


def cursor_move():
	# le.cursorBackward(True,2)
	# le.cursorBackward(True,3)
	# le.cursorForward(True,3)
	# le.cursorWordBackward(True)
	# le.cursorWordForward(True)
	# le.end(True)
	# le.home(True)
	# le.setCursorPosition(1.5)
	# print(le.cursorPosition())
	# print(le.cursorPositionAt(QPoint(55, 15)))
	# le.cursorBackward(True,2)
	# le.cursorBackward(True,2)
	# le.backspace()
	# le.del_()
	# le.clear()
	# le.setFocus()
	# le.cursorBackward(True,3)
	# # le.copy()
	# le.cut()
	# le.setCursorPosition(0)
	# le.paste()
	# le.setFocus()
	# le.setSelection(2,10)
	# le.setSelection(0,len(le.text()))
	# le.selectAll()
	# le.deselect()
	print(le.hasSelectedText())

	print(le.selectedText())
	print(le.selectionStart())
	print(le.selectionEnd())
	print(le.selectionLength())


btn.clicked.connect(cursor_move)
le.textEdited.connect(lambda val: print('文本框编辑时发射的信号:', val))
le.textChanged.connect(lambda val: print('文本框内容发生改变时发射的信号:', val))
# le.setText('xxx')
# le.returnPressed.connect(lambda :print('回车键被按下'))
# le.returnPressed.connect(lambda: le2.setFocus())
# le.editingFinished.connect(lambda :print('结束编辑'))
# le.cursorPositionChanged.connect(lambda old_Pos, new_Pos:print(old_Pos,new_Pos))
le.selectionChanged.connect(lambda :print('选中文本发生改变',le.selectedText()))

# 2.3 展示控件
window.show()
# 3. 应用程序的执行,进入到消息循环
sys.exit(app.exec_())
